package edu.fdzc.shop1.controller;

import edu.fdzc.shop1.dto.CategoryDto;
import edu.fdzc.shop1.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * DESCRIPTION
 * 商品分类相关接口
 */
@RestController
@RequestMapping("/api/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * 新增商品分类
     * @param categoryDto
     * @return
     */
    @PostMapping("/add")
    public boolean add(@RequestBody CategoryDto categoryDto) {
        //logger.debug("新增商品分类请求参数,categoryDto:{}", categoryDto);
        return categoryService.saveCategory(categoryDto);
    }
    /**
     * 获取指定分类信息
     * @param categoryId
     * @return
     */
    @GetMapping("/detail/{categoryId}")
    public CategoryDto detail(@PathVariable("categoryId") String categoryId) {
        //logger.debug("获取指定分类信息请求参数,categoryId:{}", categoryId);
        return categoryService.getCategoryById(categoryId);
    }
    /**
     * 修改分类信息
     * @param categoryDto
     * @return
     */
    @PutMapping("/update")
    public Boolean update(@RequestBody CategoryDto categoryDto) {
        //logger.debug("修改分类信息请求参数,categoryDto:{}", categoryDto);
        return categoryService.update(categoryDto);
    }
    /**
     * 删除分类
     * @param categoryId
     * @return
     */
    @DeleteMapping("/delete/{categoryId}")
    public Boolean delete(@PathVariable("categoryId") String categoryId) {
        //logger.debug("删除分类请求参数,categoryId:{}", categoryId);
        return categoryService.delete(categoryId);
    }
}
